<template>
  <div id="app">
    <div class="title">
      <p class="title-main">最新帖子</p>
      <div class="title-line"></div>
      <p class="title-text">很想给你写封信,告诉你这里的天气</p>
      <p class="title-text">昨夜的那场电影,还有我的心情</p>
    </div>

    <el-row class="content hidden-sm-and-down">
      <el-col :span="8" v-for="(item, index) in list.slice(0,3)" :key="index" class="content-card">
        <el-card :body-style="{ padding: '0px' }">
          <router-link :to="'articledetail/' + item.id"><el-image :src="'http://www.liujn.top/bbs/api' + (item.image || '/image/fatie/diushi.jpg')" class="content-image" fit="cover" lazy/></router-link>
          <div class="content-text">
            <span><b>{{ item.title }}</b></span>
            <div class="bottom clearfix">
              <time class="time">{{ item.posttime.slice(0,10) }}</time>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <div class="md hidden-md-and-up">
      <div class="md-center">
        <el-row class="content">
          <el-col v-for="(item, index) in list.slice(0,2)" :key="index" class="content-card">
            <el-card :body-style="{ padding: '0px' }">
              <router-link :to="'articledetail/' + item.id"><el-image :src="'http://www.liujn.top/bbs/api' + (item.image || '/image/fatie/diushi.jpg')" class="content-image" fit="cover" lazy/></router-link>
              <div class="content-text">
                <span><b>{{ item.title }}</b></span>
                <time class="time">{{ item.posttime.slice(0,10) }}</time>
              </div>
            </el-card>
          </el-col>
        </el-row>

        <el-row class="content">
          <el-col v-for="(item, index) in list.slice(3,5)" :key="index" class="content-card">
            <el-card :body-style="{ padding: '0px' }">
              <router-link :to="'articledetail/' + item.id"><el-image :src="'http://www.liujn.top/bbs/api' + (item.image || '/image/fatie/diushi.jpg')" class="content-image" fit="cover" lazy/></router-link>
              <div class="content-text">
                <span><b>{{ item.title }}</b></span>
                <time class="time">{{ item.posttime.slice(0,10) }}</time>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>

  </div>
</template>

<script>
import 'element-ui/lib/theme-chalk/display.css';
export default {
  name: '',
  data() {
    return {
      currentDate: new Date(),
      list: []
    }
  },
  mounted () {
    this.getArticle()
    },
  methods: {
    getArticle() {
      this.axios.get('http://www.liujn.top/bbs/api/Allposts/seek').then((res) => {
        let list = res.data;
        const handle = (property) => {
          return (a, b) => {
            const val1 = a[property];
            const val2 = b[property];
            return val1 - val2;
          };
        };
        list.sort(handle("id"));
        this.list = list.reverse();
        console.log(list);
      })
    }
  }
}
</script>

<style scoped>
  a {
    text-decoration: none
  }

  #app {
    /* height: 100%; */
    width: 100%;
  }

  .title {
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", 微软雅黑, Tahoma, Arial, sans-serif;
  }
  .title-main {
    font-size: 32px;
  }
  .title-line {
    margin: 0 auto 30px auto;
    width: 50px;
    height: 3px;
    background-color: #00c2ff;
  }
  .title-text {
    color: #888888;
    margin: 0px;
    font-size: 14px;
  }

  .content {
    width: 100%;
    margin-top: 40px;
    display: flex;
  }
  .content-card {
    margin: 0 auto;
    width: 25%;
    min-height: 500px;
    background-color: #eee;
    display: flex;
    flex-direction: column;
  }

  .content-text {
    height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .content-text span {
    font-size: 20px;
    white-space:nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content-image {
    height: 400px;
    display: block;
  }

  .time {
    font-size: 13px;
    color: #999;
  }
  
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  @media screen and (max-width: 991px) {

    .title {
      /* margin-bottom: 20px; */
      height: 25vh;
    }

    .md {
      width: 100%;
      height: 60vh;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    .md-center {
      width: 94%;
      margin: 0 auto;

    }

    .content {
      width: 100%;
      margin: 20px auto 0px auto;
      display: flex;
      height: 180px;
    }
    .content-card {
      margin: 0 auto;
      width: 48%;
      height: 180px;
      min-height: 0px;
      background-color: #eee;
      display: flex;
    }

    .content-text {
      height: 50px;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .content-text span {
      font-size: 16px;
    }

    .content-image {
      height: 130px;
      display: block;
    }

    .time {
      font-size: 13px;
      color: #999;
    }
  }
</style>
